home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / mvplot.lwm < prev    next >
Text File  |  1993-12-13  |  7KB  |  305 lines

  1. /* CMD: MathVision Plot
  2.  * Plot surface from Seven Seas Software's MathVision in modeler
  3.  * for good results, map a MathVision contour plot onto this object
  4.  * by Arnie Cachelin © 1993 NewTek, Inc.
  5.  */
  6.  
  7. arg bas
  8. call addlib "LWModelerARexx.port", 0
  9. signal on error
  10. signal on syntax
  11. if ~show('P',"MathVision") then do
  12.   notify(1,"!Can't find MathVision...","Is it running?")
  13.   exit
  14.   end
  15. ADDRESS "MathVision"
  16. OPTIONS RESULTS
  17.  
  18. MATHLIB="rexxmathlib.library"
  19. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  20.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  21.     call notify(1,"!Can't find "MATHLIB)
  22.     exit
  23.     END
  24. call addlib "rexxsupport.library", 0, -30, 0
  25.  
  26. sysnam = 'MathVision Plot'
  27. filnam = 'ENV:MVplot.state'
  28. version = 'MVPlot v1.0'
  29.  
  30. /* Setup state.  Read stored one, if any.
  31.  */
  32. Get 'Xmin' ; x1=RESULT
  33. Get Ymin ; y1=RESULT
  34. Get 'Xmax' ; x2=RESULT
  35. Get 'Ymax' ; y2=RESULT
  36. Get 'ContourAnchor' ; z1=RESULT
  37. Get 'ContourTop' ; z2=RESULT
  38. NSX  = 20
  39. NSY  = 20
  40. flip = 1
  41. tri = 1
  42. typ=2
  43.  
  44. call req_begin sysnam
  45.  
  46. id_nsx = req_addcontrol("X Segments", 'n')
  47. id_nsy = req_addcontrol("Y Segments", 'n')
  48. id_tri = req_addcontrol("Triangles", 'b')
  49. id_typ = req_addcontrol("Build: ","CH","Points Polys Curves")
  50.  
  51. call req_setval id_nsx, nsx, 20
  52. call req_setval id_nsy, nsy, 20
  53. call req_setval id_tri, tri,tri
  54. call req_setval id_typ, typ,typ
  55.  
  56. if (~req_post()) then do
  57.     call req_end
  58.     exit
  59. end
  60.  
  61. NSX = req_getval(id_nsx) % 1
  62. NSY = req_getval(id_nsx) % 1
  63. typ   = req_getval(id_typ)
  64. tri = req_getval(id_tri)
  65.  
  66. call req_end
  67.  
  68. xrange = x2 - x1
  69. yrange = y2 - y1
  70. xmesh = xrange / NSX
  71. ymesh = yrange / NSY
  72. tri_height = sqrt(3)/2
  73. ifunc = "vz =MVVal(x,y)"
  74. say ifunc
  75. vz=0
  76. zmax=vz
  77. zmin=vz
  78. call randu(time('s'))  /* Seed random number generator */
  79.  
  80. if typ=3 then call RectCurves
  81. else
  82. if tri then do
  83.   if typ=1 then call TriPoints
  84.   else call TriMesh
  85.   end
  86. else do
  87.   if typ=1 then call RectPoints
  88.   else call RectMesh
  89.   end
  90.  
  91. l1 = "Points created:" totalpoints
  92. l2 = "Polygons created:" poly
  93. l3 = "Z ranges between" zmin "and" zmax
  94. call notify 1, '!'sysnam, l1, l2, l3
  95.  
  96. exit
  97.  
  98. syntax:
  99. error:
  100.   call end_all
  101.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  102.     exit
  103.  
  104. RectMesh:
  105.     totalpoints = (NSX+1) * (NSY+1)
  106.     totalpolys  = NSX * NSY
  107.     call add_begin
  108.     call meter_begin totalpoints+2, sysnam, "Computing "totalpoints" points for "totalpolys" squares"
  109.     do y=y1 to y2 by ymesh
  110.       do x=x1 to x2 by xmesh
  111.         interpret ifunc
  112.         if vz<zmin then zmin=vz
  113.         if vz>zmax then zmax=vz     /* Just some silly stats for later */
  114. /*         if (flip) then vec =x vz y */
  115.         vec = x y vz
  116.         call add_point(vec)
  117.         call meter_step
  118.       end
  119.     end
  120.  
  121.     point=1
  122.     poly=0
  123.     call meter_begin totalpolys, sysnam, "Generating "totalpolys" Polygon Mesh"
  124.     do y=y1 to y2-ymesh by ymesh   /* Don't make wrap-around polygon */
  125.       do x=x1 to x2 by xmesh
  126.         if x<x2 then do   /* Again, Don't make wrap-around polygon! */
  127.           if (flip) then
  128.             call add_quad point point+NSX+1 point+NSX+2 point+1
  129.           else
  130.             call add_quad point point+1 point+NSX+2 point+NSX+1
  131.           poly = poly + 1
  132.           call meter_step
  133.         end
  134.         point = point + 1
  135.       end
  136.     end
  137.     call meter_end
  138.     call add_end
  139. return totalpoints
  140. /*  */
  141.  
  142. RectPoints:
  143.     totalpoints = (NSX+1) * (NSY+1)
  144.     poly=totalpoints
  145.     call add_begin
  146.     call meter_begin totalpoints+2, sysnam, "Computing "totalpoints" points for 1-point polygons"
  147.     point=1
  148.     do y=y1 to y2 by ymesh
  149.       do x=x1 to x2 by xmesh
  150.         interpret ifunc
  151.         if vz<zmin then zmin=vz
  152.         if vz>zmax then zmax=vz     /* Just some silly stats for later */
  153. /*         if (flip) then vec =x vz y */
  154.         vec = x y vz
  155.         call add_point(vec)
  156.         call add_polygon(point)
  157.         point=point+1
  158.         call meter_step
  159.       end
  160.     end
  161.     call add_end
  162. return totalpoints
  163. /*  */
  164.  
  165. RectCurves:
  166.     totalpoints = (NSX+1) * (NSY+1)
  167.     poly=NSX+1 + NSY+1
  168.     call add_begin
  169.     call meter_begin totalpoints+NSX+2, sysnam, "Computing "totalpoints" points for "poly" Curves"
  170.     crv=""
  171.     point=1
  172.     do y=y1 to y2 by ymesh
  173.       do x=x1 to x2 by xmesh
  174.  
  175.         interpret ifunc
  176.  
  177.         if vz<zmin then zmin=vz
  178.         if vz>zmax then zmax=vz
  179.  
  180. /*         if (flip) then vec =x vz y */
  181.         vec = x y vz
  182.         call add_point(vec)
  183.         crv=crv point
  184.         point=point+1
  185.         call meter_step
  186.       end
  187.       call Add_Curve(crv)
  188.       crv=""
  189.     end
  190.     do p=1 to NSX+1
  191.       do o=0 to NSY
  192.         crv=crv p+o*(NSX+1)
  193.       end
  194.       call meter_step
  195.       call Add_Curve(crv)
  196.       crv=""
  197.     end
  198.     call add_end
  199. return totalpoints
  200. /*  */
  201.  
  202. TriMesh:
  203.     totalpoints = (NSX+1) * (NSY+1)
  204.     totalpolys  = NSX * NSY * 2
  205.     call add_begin
  206.     call meter_begin totalpoints*2, sysnam, "Computing "totalpoints" points"
  207.     offset=0
  208.     rows=0
  209.     totalpoints=0
  210.  
  211.     do y=y1 to y2 by ymesh* tri_height
  212.         rows=rows+1
  213.         columns=0
  214.       if y=y2 then TopCorner.4=totalpoints
  215.       do x=x1+offset to x2+offset by xmesh
  216.  
  217.              columns = columns + 1
  218.         interpret ifunc
  219.  
  220.         if vz<zmin then zmin=vz
  221.         if vz>zmax then zmax=vz     /* Just some silly stats for later */
  222.  
  223. /*         if (flip) then vec =x vz y */
  224.         vec = x y vz
  225.         call add_point vec
  226.         totalpoints = totalpoints + 1
  227.         call meter_step
  228.       end
  229.       if y=y1 then TopCorner.2=totalpoints
  230.       if y=y2 then TopCorner.3=totalpoints
  231.         if offset=0 then offset=.5 * xmesh  /* offset alternate lines */
  232.         else offset=0
  233.     end
  234.     call meter_end
  235.  
  236.     point=1
  237.     poly=0
  238.     off=0
  239.     call meter_begin totalpolys, sysnam, "Generating "totalpolys" Polygon Mesh"
  240.     do row=0 to rows-2
  241.       if off=0 then off=1  /* Boy this feels kludgey!!! */
  242.       else off=0
  243.          do col=1 to columns - 1
  244.         if (flip) then do
  245.           call add_quad col+row*columns col+(row*columns)+1 col+((row+1)*columns)+abs(off-1)
  246.           call add_quad col+(row*columns)+off col+((row+1)*columns)+1 col+((row+1)*columns)
  247.           poly=poly+2
  248.           end
  249.         else do
  250.           call add_quad col+row*columns col+((row+1)*columns)+abs(off-1) col+(row*columns)+1
  251.           call add_quad col+(row*columns)+off col+((row+1)*columns) col+((row+1)*columns)+1
  252.           poly=poly+2
  253.           end
  254.         call meter_step
  255.       end
  256.     end
  257.     call meter_end
  258.     call add_end
  259. return totalpoints
  260. /*  */
  261.  
  262. TriPoints:
  263.     totalpoints = (NSX+1) * (NSY+1)
  264.     call add_begin
  265.     call meter_begin totalpoints*2, sysnam, "Computing "totalpoints" points for 1-point polygons"
  266.     offset=0
  267.     rows=0
  268.     totalpoints=0
  269.     point=1
  270.  
  271.     do y=y1 to y2 by ymesh* tri_height
  272.         rows=rows+1
  273.         columns=0
  274.       do x=x1+offset to x2+offset by xmesh
  275.  
  276.              columns = columns + 1
  277.         interpret ifunc
  278.  
  279.         if vz<zmin then zmin=vz
  280.         if vz>zmax then zmax=vz     /* Just some silly stats for later */
  281.  
  282. /*         if (flip) then vec =x vz y */
  283.         vec = x y vz
  284.         call add_point vec
  285.         call add_polygon point
  286.         point=point+1
  287.         call meter_step
  288.       end
  289.         if offset=0 then offset=.5 * xmesh  /* offset alternate lines */
  290.         else offset=0
  291.     end
  292.     call meter_end
  293.     totalpoints = point - 1
  294.     poly=totalpoints
  295.     call add_end()
  296. return totalpoints
  297.  
  298. MVVal: Procedure
  299.   arg vx,vy
  300.   X vx
  301.   Y vy
  302.   Get Eval "fa" ; z=RESULT
  303.   return z
  304.  
  305. /*  */